HAL LPTIM Functions

LP Timer Initialization/Deinitialization function

group LPTIM_Exported_Functions_Group1

This section provides a set of function allowing to:

Functions

hal_status_t HAL_LPTIM_Init ( hal_lptim_handle_t * hlptim , hal_lptim_t instance )

Initialization function. Initialize the LPTIM handle and associate an instance.

Parameters :
  • hlptim – Pointer to the handler of the LPTIM instance.

  • instance – One of the values of the hal_lptim_t enumeration.

Return values :
  • HAL_OK

  • HAL_INVALID_PARAM – Input parameter is invalid (only if USE_HAL_CHECK_PARAM == 1)

void HAL_LPTIM_DeInit ( hal_lptim_handle_t * hlptim )

Reset function.

Stop all current operations and reset states.

Hence:

.

  • stop the counter.

  • disable interrupts / DMA transfers.

  • clear status flags.

  • set channels’ states to RESET.

  • set global state to RESET.

Warning

Be careful if you used an external clock to have called HAL_LPTIM_SetConfigInput1() before Deinit!

Parameters :

hlptim – Pointer to the handler of the LPTIM instance.

hal_status_t HAL_LPTIM_SetDMA ( hal_lptim_handle_t * hlptim , hal_lptim_dma_index_t dma_idx , hal_dma_handle_t * hdma )

Link a DMA handle to a DMA request.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • dma_idx – Index of the DMA request.

  • hdma – Pointer to a handle of the DMA instance.

Return values :

HAL_OK

LP Timer Peripheral State, Error functions

group LPTIM_Exported_Functions_Group2

This group gathers the functions for the states and error management.

This section provides a set of functions for state and error management.

Functions

hal_lptim_state_t HAL_LPTIM_GetState ( const hal_lptim_handle_t * hlptim )

Get the low-power timer state.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_state_t – HAL LPTIM state.

hal_lptim_channel_state_t HAL_LPTIM_GetChannelState ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get the state of a channel.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Channel of interest.

Return values :

hal_lptim_channel_state_t – LPTIM channel state.

uint32_t HAL_LPTIM_GetLastErrorCodes ( const hal_lptim_handle_t * hlptim )

Retrieve the HAL LPTIM last errors.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

uint32_t

HAL LPTIM bit-mapped last errors.

Values are:

HAL_LPTIM_ERROR_NONE HAL_LPTIM_ERROR_DMA HAL_LPTIM_ERROR_TIMEOUT

LP Timer Timebase configuration and control.

group LPTIM_Exported_Functions_Group3

This group contains the functions used to configure and control the time-base unit.

Note

When the clock source is HAL_LPTIM_CLK_ENCODER_SUBMODE_[1|2|3], selection of the sources (two signals from quadrature encoders) is done with HAL_LPTIM_SetConfigEncoder().

Functions

hal_status_t HAL_LPTIM_SetConfig ( hal_lptim_handle_t * hlptim , const hal_lptim_config_t * p_config )

Configure the low-power timer time-base unit.

Note

If the clock source is set to HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_ENCODER_SUBMODE_[1|2|3], the prescaler is forced to HAL_LPTIM_CLK_SRC_DIV1.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to the time-base unit configuration structure.

Return values :
  • HAL_OK

  • HAL_ERROR – LPTIM_ISR or LPTIM_ARR write operation failed.

  • HAL_INVALID_PARAM – Input parameter is invalid. (only if USE_HAL_CHECK_PARAM == 1)

void HAL_LPTIM_GetConfig ( const hal_lptim_handle_t * hlptim , hal_lptim_config_t * p_config )

Get the configuration of the low-power timer time-base unit.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to a time-base unit configuration structure to fill.

hal_status_t HAL_LPTIM_SetMode ( hal_lptim_handle_t * hlptim , hal_lptim_mode_t mode )

Set the mode of the low-power timer time-base unit.

Warning

Calling this function while the clock source is HAL_LPTIM_CLK_ENCODER_SUBMODE_x has no effect.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • mode – The counter mode selected.

Return values :

HAL_OK

hal_lptim_mode_t HAL_LPTIM_GetMode ( const hal_lptim_handle_t * hlptim )

Get the mode of the low-power timer time-base unit.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_mode_t – Mode in which the low-power timer runs.

hal_status_t HAL_LPTIM_SetClockSource ( const hal_lptim_handle_t * hlptim , hal_lptim_clk_src_t clk_src )

Set the clock source of the low-power timer time-base unit.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • clk_src – Clock source selection.

Return values :

HAL_OK

hal_lptim_clk_src_t HAL_LPTIM_GetClockSource ( const hal_lptim_handle_t * hlptim )

Get the clock source of the low-power timer time-base unit.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_clk_src_t – Clock source of the LPTIM instance.

hal_status_t HAL_LPTIM_SetClockSourcePrescaler ( const hal_lptim_handle_t * hlptim , hal_lptim_clk_src_presc_t clk_src_presc )

Set the clock source prescaler of the low-power timer time-base unit.

Note

Clock prescaler setting has no effect if the clock source is HAL_LPTIM_CLK_ENCODER_SUBMODE_[1|2|3].

Note

The prescaler must not be used (DIV1) when the LPTIM external Input1 is sampled with the internal clock (HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS).

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • clk_src_presc – Clock source prescaler for the time base unit.

Return values :

HAL_OK

hal_lptim_clk_src_presc_t HAL_LPTIM_GetClockSourcePrescaler ( const hal_lptim_handle_t * hlptim )

Get the clock source prescaler of the low-power timer.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_clk_src_presc_t – Clock source prescaler of the LPTIM instance.

hal_status_t HAL_LPTIM_SetPeriod ( const hal_lptim_handle_t * hlptim , uint32_t period )

Set the period of the low-power timer time-base unit.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • period – Period for the time base unit.

Return values :
  • HAL_OK

  • HAL_ERROR – LPTIM_ARR write operation failed.

uint32_t HAL_LPTIM_GetPeriod ( const hal_lptim_handle_t * hlptim )

Get the period of the low-power timer.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Returns :

uint32_t Period Value

hal_status_t HAL_LPTIM_SetRepetitionCounter ( const hal_lptim_handle_t * hlptim , uint32_t repetition_counter )

Set the repetition counter of the low-power timer time-base unit.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • repetition_counter – Repetition value for the time base unit.

Return values :
  • HAL_OK

  • HAL_ERROR – LPTIM_ISR write operation failed

uint32_t HAL_LPTIM_GetRepetitionCounter ( const hal_lptim_handle_t * hlptim )

Get the value of the repetition counter of the low-power timer.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

uint32_t – Value of the repetition counter.

uint32_t HAL_LPTIM_GetCounter ( const hal_lptim_handle_t * hlptim )

Get Counter Register (LPTIMx_CNT) value.

Warning

When the LPTIM instance is running, reading the LPTIMx_CNT register can return unreliable values. So in this case it is necessary to perform two consecutive read accesses and verify that the two returned values are identical.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Returns :

Counter register value.

hal_status_t HAL_LPTIM_ResetCounter ( const hal_lptim_handle_t * hlptim )

Reset Counter Register.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK

hal_status_t HAL_LPTIM_EnableResetCounterAfterRead ( const hal_lptim_handle_t * hlptim )

Enable Reset Counter After read.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK

hal_status_t HAL_LPTIM_DisableResetCounterAfterRead ( const hal_lptim_handle_t * hlptim )

Disable Reset Counter After read.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK

hal_lptim_reset_after_read_status_t HAL_LPTIM_IsEnableResetCounterAfterRead ( const hal_lptim_handle_t * hlptim )

Check Reset Counter After read.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_reset_after_read_status_t – Registers update mode.

hal_status_t HAL_LPTIM_EnablePreload ( const hal_lptim_handle_t * hlptim )

Enable the preload.

Note

registers ARR, RCR and CCRx will be updated only at the end of the current LPTIM period.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK

hal_status_t HAL_LPTIM_DisablePreload ( const hal_lptim_handle_t * hlptim )

Disable the preload.

Note

registers ARR, RCR and CCR are updated after each APB bus access.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK

hal_lptim_preload_status_t HAL_LPTIM_IsEnabledPreload ( const hal_lptim_handle_t * hlptim )

Check preload state.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_preload_status_t – Registers update mode.

hal_status_t HAL_LPTIM_SetConfigInput1 ( const hal_lptim_handle_t * hlptim , const hal_lptim_input1_config_t * p_config )

Configure Input1.

Warning

This function must be called only after the clock source is configured.

Warning

If the clock is HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS but the filter is not HAL_LPTIM_FDIV1, or the polarity is HAL_LPTIM_INPUT1_RISING_FALLING then an auxiliary clock (one of the Low power oscillator) must be active.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to the input1 configuration structure.

Return values :
  • HAL_OK

  • HAL_ERROR – When called with clock source different from HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS.

void HAL_LPTIM_GetConfigInput1 ( const hal_lptim_handle_t * hlptim , hal_lptim_input1_config_t * p_config )

Get Input1 configuration.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to an input1 configuration structure.

hal_status_t HAL_LPTIM_SetInput1Source ( const hal_lptim_handle_t * hlptim , hal_lptim_input1_src_t input1_src )

Configure the Input1 source.

Warning

This function must be called only after the clock source is configured.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • input1_src – Source of Input1.

Return values :
  • HAL_OK

  • HAL_ERROR – When called with clock source different from HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS.

hal_lptim_input1_src_t HAL_LPTIM_GetInput1Source ( const hal_lptim_handle_t * hlptim )

Get the input1 source.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_input1_src_t – The input1 source.

hal_status_t HAL_LPTIM_SetInput1Polarity ( const hal_lptim_handle_t * hlptim , hal_lptim_input1_polarity_t polarity )

Set Input1 polarity.

Warning

This function must be called only after the clock source is configured.

Warning

An auxiliary clock (one of the Low power oscillator) must be active if the polarity is HAL_LPTIM_INPUT1_RISING_FALLING.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • polarity – polarity of Input1.

Return values :
  • HAL_OK

  • HAL_ERROR – When called with clock source different from HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS.

hal_lptim_input1_polarity_t HAL_LPTIM_GetInput1Polarity ( const hal_lptim_handle_t * hlptim )

Get Input1 polarity.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_input1_polarity_t – Input1 polarity.

hal_status_t HAL_LPTIM_SetInput1Filter ( const hal_lptim_handle_t * hlptim , hal_lptim_filter_t filter )

Configure the Input1 filter.

Note

If filtering is used, an auxiliary clock must be active.

Warning

This function must be called only after the clock source is configured.

Warning

An auxiliary clock (one of the Low power oscillator) must be active if the value of the filter is different from HAL_LPTIM_FDIV1.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • filter – Filter for Input1.

Return values :
  • HAL_OK

  • HAL_ERROR – When called with clock source different from HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS or HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS.

hal_lptim_filter_t HAL_LPTIM_GetInput1Filter ( const hal_lptim_handle_t * hlptim )

Get the input1 filter.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Returns :

hal_lptim_filter_t Filter applied to Input1.

Low-power timer start/stop service functions.

group LPTIM_Exported_Functions_Group4

This section provides a set of functions to start and stop LPTIM services.

Functions

hal_status_t HAL_LPTIM_Start ( hal_lptim_handle_t * hlptim )

Start the low-power timer in polling mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :
  • HAL_OK

  • HAL_ERROR – When there is a mismatch between the mode and the current clock source.

hal_status_t HAL_LPTIM_Stop ( hal_lptim_handle_t * hlptim )

Stop the low-power timer that was started in polling mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK

hal_status_t HAL_LPTIM_Start_IT ( hal_lptim_handle_t * hlptim )

Start the low-power timer in interrupt mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :
  • HAL_OK

  • HAL_ERROR – When there is a mismatch between the mode and the current clock source, or when enabling the interrupts failed.

hal_status_t HAL_LPTIM_Stop_IT ( hal_lptim_handle_t * hlptim )

Stop the low-power timer that was started in interrupt mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :
  • HAL_OK

  • HAL_ERROR – LPTIM_DIER write operation failed.

hal_status_t HAL_LPTIM_Start_DMA_Opt ( hal_lptim_handle_t * hlptim , const uint8_t * p_data , uint32_t size_byte , uint32_t interrupts )

Start the low-power timer in DMA mode.

Warning

HAL_LPTIM_SetDMA() is to be called with the correct DMA index (see hal_lptim_dma_index_t) before calling this function.

Parameters :
Return values :
  • HAL_OK

  • HAL_ERROR – Failed to start the DMA transfer.

  • HAL_INVALID_PARAM – Input parameter is invalid (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_Start_DMA ( hal_lptim_handle_t * hlptim , const uint8_t * p_data , uint32_t size_byte )

Start the low-power timer in DMA mode.

Warning

HAL_LPTIM_SetDMA() is to be called with the correct DMA index (see hal_lptim_dma_index_t) before calling this function.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_data – Pointer to the data buffer.

  • size_byte – Data buffer size (in bytes).

Return values :
  • HAL_OK

  • HAL_ERROR – Failed to start the DMA transfer.

  • HAL_INVALID_PARAM – Input parameter is invalid (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_Stop_DMA ( hal_lptim_handle_t * hlptim )

Stop the timer that was started in DMA mode.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

HAL_OK

Low-power timer output channel functions

group LPTIM_Exported_Functions_Group5

This group contains the functions used to configure and control the output stage of the LP Timer’s capture/compare channels.

Functions

hal_status_t HAL_LPTIM_OC_SetConfigChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , const hal_lptim_oc_config_t * p_config )

Configure the Output channel.

Parameters :
Return values :
  • HAL_OK

  • HAL_ERROR – When low-power timer PWM setup fails.

  • HAL_INVALID_PARAM – When p_config pointer is NULL (only if USE_HAL_CHECK_PARAM == 1)

void HAL_LPTIM_OC_GetConfigChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_oc_config_t * p_config )

Get the configuration of an Output Channel.

Parameters :
hal_status_t HAL_LPTIM_OC_SetChannelPolarity ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_oc_polarity_t polarity )

Set output channel’s polarity.

Warning

Ensure the channel is disabled.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel

    Output channel of interest.

    Must be one of the following values:

  • polarity – Output channel’s polarity

Return values :

HAL_OK

hal_lptim_oc_polarity_t HAL_LPTIM_OC_GetChannelPolarity ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get output channel’s polarity.

Parameters :
Returns :

hal_lptim_oc_polarity_t Output channel’s polarity mode

hal_status_t HAL_LPTIM_OC_SetChannelPulse ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , uint32_t pulse )

Program the pulse width of the output channel.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel

    Output channel of interest.

    Must be one of the following values:

  • pulse – Value pulse width needs to compare it.

Return values :
  • HAL_OK

  • HAL_ERROR – If pulse set failed.

uint32_t HAL_LPTIM_OC_GetChannelPulse ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get the pulse of the output channel.

Parameters :
Returns :

Pulse value from channel number.

hal_status_t HAL_LPTIM_OC_StartChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Start a LP-Timer’s output channel in polling mode.

Parameters :
Return values :

HAL_OK

hal_status_t HAL_LPTIM_OC_StopChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop the low-power timer output channel or output compare.

Parameters :
Return values :

HAL_OK

hal_status_t HAL_LPTIM_OC_StartChannel_IT ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Start the low-power timer output channel or output compare in interrupt mode.

Parameters :
Return values :
  • HAL_OK

  • HAL_ERROR – No flag has been given.

hal_status_t HAL_LPTIM_OC_StopChannel_IT ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop the low-power timer output channel or output compare in interrupt mode.

Parameters :
Return values :
  • HAL_OK

  • HAL_ERROR – No flags have been given.

Low-power timer input channel functions.

group LPTIM_Exported_Functions_Group6

This group contains the functions used to configure and control the input stage of the timer’s capture/compare channels.

Functions

hal_status_t HAL_LPTIM_IC_SetConfigChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , const hal_lptim_ic_config_t * p_config )

Configure an input channel.

Parameters :
Return values :
  • HAL_OK

  • HAL_ERROR – When the low-power timer PWM setup failed.

  • HAL_INVALID_PARAM – When p_config pointer is NULL (only if USE_HAL_CHECK_PARAM == 1)

void HAL_LPTIM_IC_GetConfigChannel ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_ic_config_t * p_config )

Get the configuration of an input channel.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Input channel of interest to enable.

  • p_config – Pointer on hal_lptim_ic_config_t.

hal_status_t HAL_LPTIM_IC_SetChannelSource ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_ic_src_t source )

Set input channel’s source.

Warning

Ensure the channel is disabled.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel

    Input channel of interest.

    Must be one of the following values:

  • source – Input source for the channel.

Return values :

HAL_OK

hal_lptim_ic_src_t HAL_LPTIM_IC_GetChannelSource ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get the source of a input channel.

Warning

Ensure the channel is disabled.

Parameters :
Return values :

hal_lptim_ic_src_t – channel input sources

hal_status_t HAL_LPTIM_IC_SetChannelPolarity ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_ic_polarity_t polarity )

Set input channel’s polarity.

Warning

Ensure the channel is disabled.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel

    Input channel of interest.

    Must be one of the following values:

  • polarity – input channel’s polarity.

Return values :

HAL_OK

hal_lptim_ic_polarity_t HAL_LPTIM_IC_GetChannelPolarity ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get input channel’s polarity.

Parameters :
Returns :

hal_lptim_ic_polarity_t The input polarity for the channel

hal_status_t HAL_LPTIM_IC_SetChannelFilter ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_filter_t filter )

Set input channel’s filter.

Warning

Ensure the channel is disabled.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel

    Input channel of interest.

    Must be one of the following values:

  • filter – Input filter for the channel.

Return values :

HAL_OK

hal_lptim_filter_t HAL_LPTIM_IC_GetChannelFilter ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get input channel’s filter.

Parameters :
Returns :

hal_lptim_filter_t input filter for the channel.

hal_status_t HAL_LPTIM_IC_SetChannelPrescaler ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , hal_lptim_ic_prescaler_t prescaler )

Configure the prescaler of an input channel.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel

    Input channel of interest.

    Must be one of the following values:

  • prescaler – Input prescaler for the channel.

Return values :

HAL_OK

hal_lptim_ic_prescaler_t HAL_LPTIM_IC_GetChannelPrescaler ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get the prescaler of a input channel.

Parameters :
Returns :

hal_lptim_ic_prescaler_t The input prescaler for the channel.

hal_status_t HAL_LPTIM_IC_StartChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Start a low-power timer input channel in polling mode.

Parameters :
Return values :

HAL_OK

hal_status_t HAL_LPTIM_IC_StopChannel ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop the low-power timer input channel.

Parameters :
Return values :

HAL_OK

hal_status_t HAL_LPTIM_IC_StartChannel_IT ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Start the low-power timer input channel in interrupt mode.

Parameters :
Return values :
  • HAL_ERROR – No flag has been given

  • HAL_OK – input channel has been correctly started

hal_status_t HAL_LPTIM_IC_StopChannel_IT ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop the low-power timer input channel in interrupt mode.

Parameters :
Return values :
  • HAL_ERROR – No flags have been given.

  • HAL_OK – input channel has been correctly stopped

hal_status_t HAL_LPTIM_IC_StartChannel_DMA ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , uint8_t * p_data , uint32_t size_byte )

Start the low-power timer input channel in DMA mode.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel

    Input channel of interest.

    Must be one of the following values:

  • p_data – Pointer to the data buffer

  • size_byte – Data buffer size

Return values :
  • HAL_ERROR – No flag has been given

  • HAL_OK

hal_status_t HAL_LPTIM_IC_StartChannel_DMA_Opt ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel , uint8_t * p_data , uint32_t size_byte , uint32_t interrupts )

Start the low-power timer input channel in DMA mode.

Parameters :
Return values :
  • HAL_OK

  • HAL_ERROR – No flag has been given

hal_status_t HAL_LPTIM_IC_StopChannel_DMA ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Stop a timer’s input channel that was started in DMA mode.

Parameters :
Return values :

HAL_OK

uint32_t HAL_LPTIM_IC_ReadChannelCapturedValue ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Read the captured value for a low-power timer input channel.

Parameters :
Return values :

uint32_t – Captured value

uint8_t HAL_LPTIM_IC_GetChannelFilterLatency ( const hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Get the input capture glitch filter latency.

Note

The LPTIM glitch filter and prescaler cause a latency offset in captured values.

Note

The real capture value corresponding to the input capture trigger can be calculated using the below formula: Real capture value = captured(LPTIM_CCRx) - filter latency

Parameters :
Return values :

uint8_t – Glitch filter latency in counter step unit

Low-power timer encoder functions.

group LPTIM_Exported_Functions_Group7

This group contains the functions used to configure the encoder stage of the timer.

Functions

hal_status_t HAL_LPTIM_SetConfigEncoder ( const hal_lptim_handle_t * hlptim , const hal_lptim_encoder_config_t * p_encoder )

Configure the encoder interface.

Warning

The signals frequency on both input1 and input2 must not exceed the LPTIM internal clock frequency divided by 4.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_encoder – Pointer to the encoder configuration structure.

Return values :

HAL_OK

void HAL_LPTIM_GetConfigEncoder ( const hal_lptim_handle_t * hlptim , hal_lptim_encoder_config_t * p_encoder )

Get the configuration of the low-power timer encoder interface.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_encoder – Pointer to the encoder configuration structure.

Config external trigger

group LPTIM_Exported_Functions_Group8

This section provides a set of function to configure external trigger

Functions

hal_status_t HAL_LPTIM_SetConfigExtTrigInput ( const hal_lptim_handle_t * hlptim , const hal_lptim_ext_trig_config_t * p_config )

Configure External Trigger input.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to an external trigger input configuration structure.

Return values :

HAL_OK

void HAL_LPTIM_GetConfigExtTrigInput ( const hal_lptim_handle_t * hlptim , hal_lptim_ext_trig_config_t * p_config )

Get the External Trigger input configuration.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_config – Pointer to an external trigger input configuration structure.

hal_status_t HAL_LPTIM_SetExtTrigInputSource ( const hal_lptim_handle_t * hlptim , hal_lptim_ext_trig_src_t source )

Set the External Trigger input source.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • source – Source selection for the external trigger.

Return values :

HAL_OK

hal_lptim_ext_trig_src_t HAL_LPTIM_GetExtTrigInputSource ( const hal_lptim_handle_t * hlptim )

Get the External Trigger input source.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_ext_trig_src_t – Source selected for the external trigger.

hal_status_t HAL_LPTIM_SetExtTrigInputPolarity ( const hal_lptim_handle_t * hlptim , hal_lptim_ext_trig_polarity_t polarity )

Set the External Trigger input polarity.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • polarity – Polarity of the ETR input.

Return values :

HAL_OK

hal_lptim_ext_trig_polarity_t HAL_LPTIM_GetExtTrigInputPolarity ( const hal_lptim_handle_t * hlptim )

Get the External Trigger input polarity.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_ext_trig_polarity_t – External trigger polarity.

hal_status_t HAL_LPTIM_SetExtTrigInputFilter ( const hal_lptim_handle_t * hlptim , hal_lptim_filter_t filter )

Set the External Trigger input filter.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • filter – Filter the external trigger input.

Return values :

HAL_OK

hal_lptim_filter_t HAL_LPTIM_GetExtTrigInputFilter ( const hal_lptim_handle_t * hlptim )

Get the External Trigger input filter.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

hal_lptim_filter_t – Filter for the external trigger input.

Low-power timer IRQ handler and callback functions

group LPTIM_Exported_Functions_Group9

This section provides LPTIM IRQ Handler and callback function called within the IRQ Handler

IRQ Handler:

And there register callback:

Functions

void HAL_LPTIM_IRQHandler ( hal_lptim_handle_t * hlptim )

This function handles LPTIM generic interrupts requests.

Note

Handle all low-power timer interrupt requests.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_CC_IRQHandler ( hal_lptim_handle_t * hlptim )

Low-power timer capture/compare handler.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_UPD_IRQHandler ( hal_lptim_handle_t * hlptim )

Low-power timer update handler.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_TRGI_DIR_IRQHandler ( hal_lptim_handle_t * hlptim )

Low-power timer trigger input handler.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_UpdateHalfCpltCallback ( hal_lptim_handle_t * hlptim )

Update Half Complete callback.

Function called when the DMA transfer triggered by the timer update DMA request is half completed.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_ErrorCallback ( hal_lptim_handle_t * hlptim )

DMA Error callback.

This function is called in case of a DMA transfer error.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_StopCallback ( hal_lptim_handle_t * hlptim )

DMA Stop callback.

This function is called after stopping a DMA transfer triggered by the timer update event.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_InputCaptureStopCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

DMA Channel Stop callback.

This function is called after stopping a DMA transfer triggered by a capture/compare event.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Input Channel of interest.

void HAL_LPTIM_UpdateCallback ( hal_lptim_handle_t * hlptim )

Update callback.

Function called when the timer update interrupt is generated or when the DMA transfer triggered by the timer update DMA request is completed.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_RepUpdateCallback ( hal_lptim_handle_t * hlptim )

Repetition Update Callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_TriggerCallback ( hal_lptim_handle_t * hlptim )

Trigger callback.

Function called when the timer trigger interrupt is generated or when the DMA transfer triggered by the timer trigger DMA request is completed.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_InputCaptureCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Input Capture Callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – input channel of interest to enable.

void HAL_LPTIM_InputCaptureHalfCpltCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Callback for the DMA Half Complete transfer triggered by an Input Capture event.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – input channel of interest to enable.

void HAL_LPTIM_InputOverCaptureCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Input Over Capture callback.

Function called when an input over capture interrupt is generated.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – input channel of interest to enable.

void HAL_LPTIM_CompareMatchCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Compare match Callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Output channel of interest to enable.

void HAL_LPTIM_CompareUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_t channel )

Compare update Callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • channel – Output channel of interest to enable.

void HAL_LPTIM_AutoReloadMatchCallback ( hal_lptim_handle_t * hlptim )

AutoReload Match callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_AutoReloadUpdateCallback ( hal_lptim_handle_t * hlptim )

Autoreload Update callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_DirectionUpCallback ( hal_lptim_handle_t * hlptim )

Direction UP callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

void HAL_LPTIM_DirectionDownCallback ( hal_lptim_handle_t * hlptim )

Direction Down callback.

Warning

This weak function must not be modified. When the callback is needed, it is overridden in the user file.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

hal_status_t HAL_LPTIM_RegisterErrorCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the DMA Error.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterStopCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Stop callback.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterChannelStopCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Channel Stop callback.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Update Event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterUpdateHalfCpltCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the DMA Half Complete transfer triggered on Update event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterRepUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for Repetition Update.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterTriggerCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Trigger event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterInputCaptureCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Input Capture event.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterInputCaptureHalfCpltCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Input Capture Half Complete.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterOverCaptureCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for Over Capture.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterCompareMatchCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Compare Match.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterCompareUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_channel_cb_t fct )

Callback registration for the Compare Update.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterAutoReloadUpdateCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Autoreload Update.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterAutoReloadMatchCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Autoreload Match.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterDirectionUpCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Direction UP changes.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

hal_status_t HAL_LPTIM_RegisterDirectionDownCallback ( hal_lptim_handle_t * hlptim , hal_lptim_cb_t fct )

Callback registration for the Direction Down changes.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • fct – Function to register as callback.

Return values :
  • HAL_OK – Register correctly setup

  • HAL_INVALID_PARAM – fct is NULL (only if USE_HAL_CHECK_PARAM == 1)

Low-power timer user data setter and getter.

group LPTIM_Exported_Functions_Group10

The user data pointer, *p_user_data, in the HAL LPTIM handle allows user to associate applicative user data to the HAL LPTIM handle. The two functions in this group give an application the possibility to store and retrieve user data pointer into and from the handle.

Functions

void HAL_LPTIM_SetUserData ( hal_lptim_handle_t * hlptim , const void * p_user_data )

Store User Data pointer into the handle.

Parameters :
  • hlptim – Pointer to the handle of the LPTIM instance.

  • p_user_data – Pointer to the user data.

const void * HAL_LPTIM_GetUserData ( const hal_lptim_handle_t * hlptim )

Retrieve User Data pointer from the handle.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :

Pointer – to the user data.

Peripheral clock frequency for LPTIMx

group LPTIM_Exported_Functions_Group11

Get clock frequency depends on instance used.

Functions

uint32_t HAL_LPTIM_GetClockFreq ( const hal_lptim_handle_t * hlptim )

Return the peripheral clock frequency for LPTIMx.

Parameters :

hlptim – Pointer to the handle of the LPTIM instance.

Return values :
  • uint32_t – Frequency in Hz

  • 0 – source clock of the lptimx not configured or not ready